package com.lianxueda.drawing.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lianxueda.drawing.domain.dto.AdminQueryDTO;
import com.lianxueda.drawing.domain.pojo.Admins ;
import com.lianxueda.drawing.domain.vo.PageVO;
import com.lianxueda.drawing.service.AdminsService;
import com.lianxueda.drawing.mapper.AdminsMapper ;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
* @author 29264
* @description 针对表【admins(管理员表)】的数据库操作Service实现
* @createDate 2024-08-20 11:52:12
*/
@Service
public class AdminsServiceImpl extends ServiceImpl<AdminsMapper, Admins>
    implements AdminsService{

    @Override
    public PageVO searchPage(AdminQueryDTO aqd) {
        LambdaQueryWrapper<Admins> qc = new LambdaQueryWrapper<>();
        if(aqd.getId()!=null){
            qc.eq(Admins::getId,aqd.getId());
        }
        if(aqd.getStatus()!=null){
            qc.eq(Admins::getStatus,aqd.getStatus());
        }
        qc.like(StringUtils.hasText(aqd.getUsername()),Admins::getUsername,aqd.getUsername());
        qc.like(StringUtils.hasText(aqd.getPhone()),Admins::getPhone,aqd.getPhone());

        IPage<Admins> page = new Page<>(aqd.getCurPage(),aqd.getPageSize());
        qc.orderByDesc(Admins::getId);
        IPage<Admins> pageResult = getBaseMapper().selectPage(page, qc);

        PageVO<Admins> pageVO = new PageVO<>();
        pageVO.setCurrentPage(pageResult.getCurrent());
        pageVO.setPageSize(pageResult.getSize());
        pageVO.setTotal(pageResult.getTotal());
        pageVO.setList(pageResult.getRecords());
        return pageVO;

    }
}




